/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Modele;

/**
 *
 * @author Raphaël
 */
public class Forme {

    public Forme() {
        super();
        build();
    }

    public void build() {
        this.numero = 0;
        this.orientation = 1;
        this.coords = new int[2];
        this.coords[0] = 0;
        this.coords[1] = 0;
    }

    public int numero;
    public int orientation;
    public int[] coords;
    public int[][] tabMatrice = {
        //FORME_VIDE
        {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
        },
        //FORME_O (1-4)
        {0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0
        },
        {0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0
        },
        {0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0
        },
        {0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0
        },
        //FORME_I (5-8)
        {0, 0, 2, 0, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0, 2, 0
        },
        {0, 0, 0, 0, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0
        },
        {0, 0, 2, 0, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0, 2, 0
        },
        {0, 0, 0, 0, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0
        },
        //FORME_S (9-12)
        {0, 0, 0, 0, 0, 0, 3, 3, 0, 3, 3, 0, 0, 0, 0, 0
        },
        {0, 0, 3, 0, 0, 0, 3, 3, 0, 0, 0, 3, 0, 0, 0, 0
        },
        {0, 0, 0, 0, 0, 0, 3, 3, 0, 3, 3, 0, 0, 0, 0, 0
        },
        {0, 0, 3, 0, 0, 0, 3, 3, 0, 0, 0, 3, 0, 0, 0, 0
        },
        //FORME_Z (13-16)
        {0, 0, 0, 0, 0, 4, 4, 0, 0, 0, 4, 4, 0, 0, 0, 0
        },
        {0, 0, 0, 4, 0, 0, 4, 4, 0, 0, 4, 0, 0, 0, 0, 0
        },
        {0, 0, 0, 0, 0, 4, 4, 0, 0, 0, 4, 4, 0, 0, 0, 0
        },
        {0, 0, 0, 4, 0, 0, 4, 4, 0, 0, 4, 0, 0, 0, 0, 0
        },
        //FORME_L (17-20)
        {0, 0, 0, 0, 0, 5, 5, 5, 0, 5, 0, 0, 0, 0, 0, 0
        },
        {0, 0, 5, 0, 0, 0, 5, 0, 0, 0, 5, 5, 0, 0, 0, 0
        },
        {0, 0, 0, 5, 0, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0
        },
        {0, 5, 5, 0, 0, 0, 5, 0, 0, 0, 5, 0, 0, 0, 0, 0
        },
        //FORME_J (21-24)
        {0, 0, 0, 0, 0, 6, 6, 6, 0, 0, 0, 6, 0, 0, 0, 0
        },
        {0, 0, 6, 6, 0, 0, 6, 0, 0, 0, 6, 0, 0, 0, 0, 0
        },
        {0, 6, 0, 0, 0, 6, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0
        },
        {0, 0, 6, 0, 0, 0, 6, 0, 0, 6, 6, 0, 0, 0, 0, 0
        },
        //FORME_T (25-28)
        {0, 0, 0, 0, 0, 7, 7, 7, 0, 0, 7, 0, 0, 0, 0, 0
        },
        {0, 0, 7, 0, 0, 0, 7, 7, 0, 0, 7, 0, 0, 0, 0, 0
        },
        {0, 0, 7, 0, 0, 7, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0
        },
        {0, 0, 7, 0, 0, 7, 7, 0, 0, 0, 7, 0, 0, 0, 0, 0
        }
    };

    public int[] getMatrice() {
        if (this.numero != 0) {
            return this.tabMatrice[(((this.numero - 1) * 4) + this.orientation)];
        } else {
            return this.tabMatrice[0];
        }
    }

    public int getValeur(int x, int y) {
        if (this.numero != 0) {
            return this.tabMatrice[(((this.numero - 1) * 4) + this.orientation)][(y) * 4 + x];
        } else {
            return 0;
        }
    }

    public int getNumero() {
        return this.numero;
    }

    public void setNumero(int numero) {
        this.numero = numero;
    }

    public void setForme(int num, int orient) {
        this.numero = num;
        this.orientation = orient;
    }

    public void setCoord(int x, int y) {
        this.coords[0] = x;
        this.coords[1] = y;
    }

    public int[] getCoord() {
        int[] coord = new int[2];
        coord[0] = this.coords[0];
        coord[1] = this.coords[1];
        return coord;

    }

    public void setOrientation(int o) {
        this.orientation = o;
    }

    public int getOrientation() {
        return this.orientation;
    }

    public void effacerPiece(Forme piece) {
        piece.numero = 0;
        piece.orientation = 1;
        piece.coords[0] = 0;
        piece.coords[1] = 0;
    }

    public void copierForme(Forme piece1, Forme piece2) {
        piece2.numero = piece1.numero;
        piece2.orientation = piece1.orientation;
        piece2.coords[0] = piece1.coords[0];
        piece2.coords[1] = piece1.coords[1];
    }

    public void augmenteOrientation() {
        if (this.numero != 0) {

            switch (this.orientation) {
                case 1:
                case 2:
                case 3:
                    this.orientation++;

                    break;
                case 4:
                    this.orientation = this.orientation - 3;

                    break;
                default:
                    this.orientation = 1;
                    break;
            }
        }
    }

}
